package com.ruoyi.web.controller.system;

import java.util.Map;
import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.ms.dataAuth.dto.DataAuthAnalysisMapperDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDataAuth;
import com.ruoyi.system.service.ISysDataAuthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据权限信息Controller
 *
 * @author ruoyi
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/system/dataAuth")
public class SysDataAuthController extends BaseController {
    @Autowired
    private ISysDataAuthService sysDataAuthService;

    /**
     * 查询数据权限信息列表-分页
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuth:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        IPage<SysDataAuth> page = sysDataAuthService.selectSysDataAuthPage(params);
        return getDataTableMp(page);
    }

    /**
     * 导出数据权限信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuth:export')")
    @Log(title = "数据权限信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody Map<String, Object> params) {
        IPage<SysDataAuth> page = sysDataAuthService.selectSysDataAuthPage(params);
        ExcelUtil<SysDataAuth> util = new ExcelUtil<SysDataAuth>(SysDataAuth.class);
        util.exportExcel(response, page.getRecords(), "数据权限信息数据");
    }

    /**
     * 获取数据权限信息详细信息-根据主键查询
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuth:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(sysDataAuthService.selectSysDataAuthById(id));
    }

    /**
     * 新增数据权限信息
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuth:add')")
    @Log(title = "数据权限信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDataAuth sysDataAuth) {
        return toAjax(sysDataAuthService.insertSysDataAuth(sysDataAuth));
    }

    /**
     * 修改数据权限信息
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuth:edit')")
    @Log(title = "数据权限信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDataAuth sysDataAuth) {
        return toAjax(sysDataAuthService.updateSysDataAuth(sysDataAuth));
    }

    /**
     * 删除数据权限信息
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuth:remove')")
    @Log(title = "数据权限信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysDataAuthService.deleteSysDataAuthByIds(ids));
    }


    /**
     * 获取当前所有已经解析含有@MsDataAuth注解的Mapper类信息
     **/
    @PostMapping("/getPathNameSelect")
    public AjaxResult getPathNameSelect() {
        Map<String, List<DataAuthAnalysisMapperDto>> result = sysDataAuthService.getPathNameSelect();
        return success(result);
    }
}
